#include "Vector.h"

Vector::Vector(float a, float b)
{
	x = a;
	y = b;
}
Vector::Vector()
{
	x = -1;
	y = -1;
}
Vector::~Vector()
{
}
void Vector::addVector(Vector *v)
{
	x += v->getX();
	y += v->getY();
}
void Vector::subVector(Vector *v)
{
	x -= v->getX();
	y -= v->getY();
}
void Vector::rotateVector(float angle)
{
	float c = cos(angle);
	float s = sin(angle);
	float a = x;
	x = a*c + y*s;
	y = -a*s + y*c;
}
void Vector::rotateVector(float c, float s)
{
	float a = x;
	x = a*c + y*s;
	y = -a*s + y*c;
}
Vector *Vector::projectVector(Vector *v)
{		
	float dp = dotProduct(v);
	float mag = v->magnitude();
	float projx = dp / v->getX() / (mag*mag);
	float projy = dp / v->getY() / (mag*mag);
	
	return (new Vector(projx, projy));
}
float Vector::dotProduct(Vector *v)
{
	return (x * v->getX() + y * v->getY());
}
void Vector::normalize()
{
	float mag = magnitude();
	x /= mag;
	y /= mag;
}
float Vector::magnitude()
{
	return (sqrt((x*x)+(y*y)));
}
